#include "sqlite.hpp"
#include <cassert>

int select_callback(void *arg, int count, char **col, char **name)
{
    vector<string> *arry = static_cast<vector<string> *>(arg);
    for (int i = 0; i < count; ++i)
        arry->push_back(col[i]);
    return 0;
}
int main()
{
    const string filename = "./test.db";
    SqliteHelper sqlite(filename);
    assert(sqlite.open());

    const string sql = "create table if not exists stu(id int primary key, name varchar(32), age int);";
    sqlite.exec(sql, nullptr, nullptr);

    // const string insert_sql = "insert into stu values(1, '小明', 18), (2, '小王', 20),(3, '小红', 19);";
    // sqlite.exec(insert_sql, nullptr, nullptr);
    // const string update_sql = "update stu set name='小张' where id=1;";
    // sqlite.exec(update_sql, nullptr, nullptr);
    // const string delete_sql = "delete from stu where id=3;";
    // sqlite.exec(delete_sql, nullptr, nullptr);
    const string select_sql = "select name from stu;";
    vector<string> arry;
    sqlite.exec(select_sql, select_callback, &arry);
    for (auto &str : arry)
        cout << str << endl;
    sqlite.close();
    return 0;
}